# -*- mode: python; coding: utf-8; -*-
##--------------------------------------------------------------------------##
##
## Copyright (C) 1998-2003 Markus Oberhumer <markus@oberhumer.com>
## Copyright (C) 2003 Mt. Hood Playing Card Co.
## Copyright (C) 2005-2010 Skomoroh <skomoroh@users.sourceforge.net>
## Copyright (C) 2010-2013 Jeremy Austin-Bardo <tjaustinbardo@gmail.com>
##
## This program is free software: you can redistribute it and/or modify
## it under the terms of the GNU General Public License as published by
## the Free Software Foundation, either version 3 of the License.
##
## This program is distributed in the hope that it will be useful,
## but WITHOUT ANY WARRANTY; without even the implied warranty of
## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
## GNU General Public License for more details.
##
## You should have received a copy of the GNU General Public License
## along with this program.  If not, see <http://www.gnu.org/licenses/>.
##
##--------------------------------------------------------------------------##
__docformat__ = 'restructuredtext en'

from ... import formlib as layout
from ... import hint as hint
from ... import pilelib as stack
from ...forms import gypsy as GypsyLayout
from ...gamelib import info as gi, game
from ...packlib import info as cs
from ...piles import hexadeck as xstack
from ...utillib.misc import kwdefault

GT, SL = gi.GT, gi.SL
Wrap = stack.StackWrapper


class TenByEight(cs.HexA_Deck, game.Game):
    """
    Finish 2 deck on _foundation_.

    :CVariables:
      _layout_ : pysollib.layout.Layout
        .. pysollib.gypsy.GypsyLayout

        - row [10 horz N foundation, vert offset]
        - talon [1 SE, no offset]
        - waste [1 W talon, no offset]
        - foundation [10 over 2 col E, no offset, no trump]

      _talon_ : pysollib.stack.Stack
        .. pysollib.stack.WasteTalon (max_rounds=INFINITE)

        Deal 1 card per `s.waste` on click. Unlimited redeals.

      _waste_ : pysollib.stack.Stack
        .. pysollib.stack.WasteStack

        Init 1 card. Build none. Play top.

      _foundation_ : pysollib.stack.Stack
        .. pysollib.stack.SS_Foundation

        Build up in rank by same suit. Play top. No trump.

      _row_ : pysollib.stack.Stack
        .. pysollib.stacks.hexadeck.TW_AC_RowStack (base_rank=x10)

        Init 8 card. Build down in rank by alt color with trump wild. Play
        seq with trump in rank.

      _hint_ : pysollib.hint.AbstractHint
        .. pysollib.hint.CautiousDefaultHint
    """
    __info__ = dict(id=0x1eecf, name='10 × 8', category=cs.TYPE_HEXADECK,
                    game_type=GT.GYPSY, decks=2, redeals=-1, version='0.50fc',
                    skill_level=SL.BALANCED)
    __author__ = 'Mt. Hood Playing Card'
    __version__ = 7.70

    _layout_ = GypsyLayout.GypsyLayout
    _talon_ = Wrap(stack.WasteTalon, max_rounds=cs.INFINITE)
    _waste_ = stack.WasteStack
    _foundation_ = stack.SS_Foundation
    _row_ = xstack.TW_AC_RowStack
    _hint_ = hint.CautiousDefaultHint

    def _create_game(self, **kw):
        kwdefault(kw, rows=10, playcards=30, trump=True)
        return super(TenByEight, self)._create_game(**kw)

    def _start(self, rows=8, **kw):
        talon = self.s['talon']
        for i in range(rows - 1):
            talon.dealRow(frames=0)
        self._play_sound('deal')
        talon.dealRow()
        talon.deal_cards()


class MagesGame(TenByEight):
    """
    Finish 1 deck on _foundation_.

    :CVariables:
      _layout_ : pysollib.layout.Layout
        .. pysollib.gypsy.GypsyLayout

        - row [12 horz N foundation, vert offset]
        - talon [1 SE, no offset]
        - waste [1 W talon, no offset]
        - foundation [10 over 2 col E, no offset, no trump]

      _talon_ : pysollib.stack.Stack
        .. pysollib.stack.WasteTalon (max_rounds=INFINITE)
        Deal 1 card per `s.waste` on click. Unlimited redeals.

      _waste_ : pysollib.stack.Stack
        .. pysollib.stack.WasteStack
        Init 1 card. Build none. Play top.

      _foundation_ : pysollib.stack.Stack
        .. pysollib.stack.SS_Foundation
        Build up in rank by same suit. Play top. No trump.

      _row_ : pysollib.stack.Stack
        .. pysollib.stacks.hexadeck.TW_AC_RowStack (base_rank=x10)
        Init 5 card outer 4, 6 card inner 8. Build down in rank by alt color
        with trump wild. Play seq with trump in rank.

      _hint_ : pysollib.hint.AbstractHint
        .. pysollib.hint.CautiousDefaultHint
    """
    __info__ = dict(id=0x1eed5, name='Mageʼs Game', category=cs.TYPE_HEXADECK,
                    game_type=GT.GYPSY, decks=1, skill_level=SL.BALANCED,
                    version='0.50fc')
    __author__ = 'Mt. Hood Playing Card'
    __version__ = 7.70

    _talon_ = stack.InitialDealTalon

    def _create_game(self, **kw):
        kwdefault(kw, rows=12, texts=False, playcards=20)
        return super(MagesGame, self)._create_game(**kw)

    def _start(self, rows=6):
        talon = self.s['talon']
        for i in range(rows - 2):
            talon.dealRow(frames=0)
        self._play_sound('deal')
        talon.dealRow()
        talon.dealRow(rows=self.s['rows'][2:10])

PROVIDES = [MagesGame, TenByEight]